<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Quick format message</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="messageformatter.create.html">« MessageFormatter::create</a></li>
      <li style="float: right;"><a href="messageformatter.format.html">MessageFormatter::format »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.messageformatter.html">MessageFormatter</a></li>
    <li>Quick format message</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="messageformatter.formatmessage" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MessageFormatter::formatMessage</h1>
  <h1 class="refname">msgfmt_format_message</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL intl &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">MessageFormatter::formatMessage</span> -- <span class="refname">msgfmt_format_message</span> &mdash; <span class="dc-title">Quick format message</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-messageformatter.formatmessage-description">
  <h3 class="title">说明</h3>
  <p class="para">
   面向对象风格
  </p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>MessageFormatter::formatMessage</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$pattern</code></span>, <span class="methodparam"><span class="type">array</span> <code class="parameter">$values</code></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   过程化风格
  </p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>msgfmt_format_message</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$pattern</code></span>, <span class="methodparam"><span class="type">array</span> <code class="parameter">$values</code></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   Quick formatting function that formats the string without having to
   explicitly create the formatter object. Use this function when the format
   operation is done only once and does not need any parameters or state to be
   kept or when wanting to customize the output by providing additional context to ICU directly.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-messageformatter.formatmessage-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">locale</code></dt>

     <dd>

      <p class="para">
       The locale to use for formatting locale-dependent parts
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">pattern</code></dt>

     <dd>

      <p class="para">
       The pattern <span class="type">string</span> to insert things into.
       The pattern uses an &#039;apostrophe-friendly&#039; syntax;
       see <a href="https://unicode-org.github.io/icu/userguide/format_parse/messages/#quotingescaping" class="link external">&raquo;&nbsp;Quoting/Escaping</a> for details.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">values</code></dt>

     <dd>

      <p class="para">
       The <span class="type">array</span> of values to insert into the format <span class="type">string</span>
      </p>
     </dd>

    
   </dl>

  </p>
 </div>



 <div class="refsect1 returnvalues" id="refsect1-messageformatter.formatmessage-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The formatted pattern string or <strong><code>false</code></strong> if an error occurred
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-messageformatter.formatmessage-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2369">
   <p><strong>示例 #1 <span class="function"><strong>msgfmt_format_message()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">msgfmt_format_message</span><span style="color: #007700">(</span><span style="color: #DD0000">"en_US"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"{0,number,integer}&nbsp;monkeys&nbsp;on&nbsp;{1,number,integer}&nbsp;trees&nbsp;make&nbsp;{2,number}&nbsp;monkeys&nbsp;per&nbsp;tree\n"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">4560</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">123</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4560</span><span style="color: #007700">/</span><span style="color: #0000BB">123</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #0000BB">msgfmt_format_message</span><span style="color: #007700">(</span><span style="color: #DD0000">"de"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"{0,number,integer}&nbsp;Affen&nbsp;auf&nbsp;{1,number,integer}&nbsp;Bäumen&nbsp;sind&nbsp;{2,number}&nbsp;Affen&nbsp;pro&nbsp;Baum\n"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">4560</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">123</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4560</span><span style="color: #007700">/</span><span style="color: #0000BB">123</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="example-2370">
   <p><strong>示例 #2 OO example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">MessageFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">formatMessage</span><span style="color: #007700">(</span><span style="color: #DD0000">"en_US"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"{0,number,integer}&nbsp;monkeys&nbsp;on&nbsp;{1,number,integer}&nbsp;trees&nbsp;make&nbsp;{2,number}&nbsp;monkeys&nbsp;per&nbsp;tree\n"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">4560</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">123</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4560</span><span style="color: #007700">/</span><span style="color: #0000BB">123</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #0000BB">MessageFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">formatMessage</span><span style="color: #007700">(</span><span style="color: #DD0000">"de"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"{0,number,integer}&nbsp;Affen&nbsp;auf&nbsp;{1,number,integer}&nbsp;Bäumen&nbsp;sind&nbsp;{2,number}&nbsp;Affen&nbsp;pro&nbsp;Baum\n"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">4560</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">123</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4560</span><span style="color: #007700">/</span><span style="color: #0000BB">123</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <p class="para">以上例程会输出：</p>
  <div class="example-contents screen">
<div class="cdata"><pre>
4,560 monkeys on 123 trees make 37.073 monkeys per tree
4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum
</pre></div>
  </div>
  <div class="example" id="example-2371">
   <p><strong>示例 #3 Instructing ICU to format currency with common and with narrow currency symbol</strong></p>
   <div class="example-contents"><p>Requires ICU ≥ 67.</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">msgfmt_format_message</span><span style="color: #007700">(</span><span style="color: #DD0000">"cs_CZ"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"{0,&nbsp;number,&nbsp;::&nbsp;currency/CAD}"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">123.45</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #0000BB">msgfmt_format_message</span><span style="color: #007700">(</span><span style="color: #DD0000">"cs_CZ"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"{0,&nbsp;number,&nbsp;::&nbsp;currency/CAD&nbsp;unit-width-narrow}"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">123.45</span><span style="color: #007700">));</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
123,45 CA$
123,45 $
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-messageformatter.formatmessage-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="messageformatter.create.html" class="function" rel="rdfs-seeAlso">msgfmt_create()</a> - Constructs a new Message Formatter</span></li>
    <li class="member"><span class="function"><a href="messageformatter.parse.html" class="function" rel="rdfs-seeAlso">msgfmt_parse()</a> - Parse input string according to pattern</span></li>
    <li class="member"><span class="function"><a href="messageformatter.geterrorcode.html" class="function" rel="rdfs-seeAlso">msgfmt_get_error_code()</a> - Get the error code from last operation</span></li>
    <li class="member"><span class="function"><a href="messageformatter.geterrormessage.html" class="function" rel="rdfs-seeAlso">msgfmt_get_error_message()</a> - Get the error text from the last operation</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>